package com.situ.company.project.service.impl;

import java.util.List;

import com.situ.company.employee.model.EmployeeModel;
import com.situ.company.project.dao.IProjectDao;
import com.situ.company.project.dao.impl.ProjectDaoImpl;
import com.situ.company.project.model.ProjectModel;
import com.situ.company.project.service.IProjectService;

public class ProjectServiceImpl implements IProjectService{
	
	private IProjectDao dao = new ProjectDaoImpl();

	@Override
	public String insert(ProjectModel model) {
		ProjectModel mdb=selectModel(model);
		if(mdb!=null) {
			return "repeat";
		}
		return dao.insert(model)+"";
	}

	@Override
	public String delete(ProjectModel model) {
		Integer res=dao.delete(model);
		return res==null?null:res.toString();
	}

	@Override
	public String update(ProjectModel model) {
		return dao.updateActive(model)+"";
	}

	@Override
	public List<ProjectModel> selectList(ProjectModel model) {
		String code = model.getCode();
		model.setCode(code == null?"%" : "%" + code + "%");
		String name = model.getName();
		model.setName(name == null?"%" : "%" + name + "%");
		return dao.selectList(model);
	}

	@Override
	public ProjectModel selectModel(ProjectModel model) {
		return dao.selectModel(new ProjectModel(model.getCode()));
	}

	@Override
	public Integer selectCount(ProjectModel model) {
		ProjectModel m1 = new ProjectModel();
		String code = model.getCode();
		m1.setCode(code == null?"%" : "%" + code + "%");
		String name = model.getName();
		m1.setName(name == null?"%" : "%" + name + "%");
		return dao.selectCount(m1);
	}

}
